<?php

namespace app\elastic;

use app\elasticquent\Elastic;

class ProductElastic extends Elastic
{
    protected $collection = 'kdy';

    public $indexName = 'product';

    public $aliasName = 'product_alias';

    protected $fileds = [

    ];

    protected $settings = [
        'number_of_shards' => 1, //分片数 集群节点的1.5倍
        'number_of_replicas' => 1, //副本数
        'analysis' => [
            'analyzer' => [
                'ik_smart_py' => [
                    'type'=>'custom',
                    'tokenizer'=>'ik_smart',
                    'filter' => 'py_filter'
                ],
                'ik_max_word_py' => [
                    'type'=>'custom',
                    'tokenizer'=>'ik_max_word',
                    'filter' => 'py_filter'
                ]
            ],
            'filter' => [
                'py_filter' => [
                    'type' => 'pinyin',
                    'keep_separate_first_letter' => true,
                    'keep_full_pinyin' => true,
                    'keep_original' => true,
                    'limit_first_letter_length' => 16,
                    'lowercase' => true,
                    'remove_duplicated_term' => true
                ]
            ]
        ]
    ];

    protected $mappings = [
        'properties' => [
            'goods_id' => ['type' => 'integer'],
            'goods_name'=>['type' => 'text','analyzer' => 'ik_max_word_py','search_analyzer' => 'ik_smart_py'],
            'category_id' => ['type' => 'integer'],
            'brand_id' => ['type' => 'integer'],
            'goods_type' => ['type' => 'byte'],//实物或虚拟商品标志 1实物商品 0 虚拟商品 2 F码商品
            'market_price' => ['type' => 'scaled_float','scaling_factor' => 100],//市场价
            'price' => ['type' => 'scaled_float','scaling_factor' => 100],//商品原价格
            'shipping_fee' => ['type' => 'scaled_float','scaling_factor' => 100],//运费 0为免运费
            'clicks' => ['type' => 'integer'],//商品点击数量
            'sales' => ['type' => 'integer'],//销售数量
            'evaluates' => ['type' => 'integer'],//评价数
            'keywords' => ['type' => 'keyword'],//商品关键词
            'state' => ['type' => 'byte'],//商品状态 0下架，1正常，10违规（禁售）
            'sort' => ['type' => 'integer'],//排序
            'create_time' => ['type' => 'date','format'=>'yyyy-MM-dd HH:mm:ss||epoch_millis'],//商品添加时间
            'update_time' => ['type' => 'date','format'=>'yyyy-MM-dd HH:mm:ss||epoch_millis'],//商品编辑时间
            'picture' => ['type' => 'integer','index' => false],//商品主图
            'img_id_array' => ['type' => 'keyword','index' => false],//商品图片序列
            'description' => ['type' => 'text','index'=>false],//商品详情
            'data_source' => ['type' => 'byte'],
            'goods_spec_format' => [
                'type' => 'nested',
                'properties' => [
                    'spec_name' => ['type' => 'keyword'],
                    'spec_id' => ['type' => 'integer'],
                    'value' => [
                        'type' => 'nested',
                        'properties' => [
                            'spec_value_name' => ['type' => 'keyword'],
                            'spec_name' => ['type' => 'keyword'],
                            'spec_id' => ['type' => 'integer'],
                            'spec_value_id' => ['type' => 'integer'],
                            'spec_show_type' => ['type' => 'byte'],
                            'spec_value_data' => ['type' => 'keyword']
                        ]
                    ],
                ],
            ],
            'skus' => [
                'type' => 'nested',
                'properties' => [
                    'sku_id' => ['type' => 'integer'],
                    'goods_id' => ['type' => 'integer'],
                    'sku_name' => ['type' => 'text','analyzer' => 'ik_max_word_py','search_analyzer' => 'ik_smart_py'],
                    'attr_value_items' => ['type' => 'keyword'],
                    'market_price' => ['type' => 'scaled_float','scaling_factor' => 100],
                    'price' => ['type' => 'scaled_float','scaling_factor' => 100],
                    'stock' => ['type' => 'integer'],
                ]
            ],
        ]
    ];

}